<template>
  <view class="container">
    <view class="title">
      <text>您的自测得分为：</text>
    </view>
    <view class="score" :class="totalScore < 50 ? 'low' : 'high'">
      <text>{{ totalScore }}</text>
    </view>
    <view class="information">
      <view class="grade" :class="totalScore < 50 ? 'low' : 'high'">
        <text v-if="totalScore < 50">低风险</text>
        <text v-else>高风险</text>
      </view>
      <view class="tip">
        {{ currentQuestionnaire.detail }}
      </view>
    </view>
    <view class="back">
      <button class="back-btn" @click="toBack">返回量表列表</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { useQuestionnaireStore } from '@/store/questionnaire'
const questionnaireStore = useQuestionnaireStore()
const totalScore = computed(() => questionnaireStore.totalScore)
const currentQuestionnaire = computed(() => questionnaireStore.currentQuestionnaire)
const toBack = () => {
  uni.navigateBack({
    delta: 2, // 返回上两级页面
  })
}
</script>

<style lang="scss" scoped>
.container {
  padding: 40px;
  width: 100vw;
  background: linear-gradient(180deg, rgba(215, 229, 247, 1) 0%, rgba(217, 234, 251, 0) 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  font-weight: bold;
  font-size: 19px;
  margin-top: 20px;
  color: #5b5b5b;
}

.score {
  margin-top: 40px;
  font-size: 40px;
  width: 170px;
  height: 170px;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  &.low {
    background: linear-gradient(0deg, rgba(144, 238, 144, 1) 0%, rgba(144, 238, 144, 0) 100%);
    color: #339931;
  }
  &.high {
    background: linear-gradient(0deg, rgba(255, 99, 99, 1) 0%, rgba(255, 99, 99, 0) 100%);
    color: brown;
  }
}

.information {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  .grade {
    margin-top: 20px;
    font-weight: bold;
    font-size: 20px;
    &.low {
      color: #339931;
    }
    &.high {
      color: #b9251a;
    }
  }
  .tip {
    margin-top: 30px;
    font-size: 14px;
  }
}
.back {
  width: 100%;
  margin-top: 30px;
  .back-btn {
    width: 80%;
    background-color: #0075fe;
    border-radius: 12px;
    color: #eee;
    margin-top: 20px;
    margin-bottom: 30px;
  }
}
</style>
